<!--
 * @Author: summer12138 1343364145@qq.com
 * @Date: 2023-05-20 21:53:30
 * @LastEditors: summer12138 1343364145@qq.com
 * @LastEditTime: 2023-05-20 23:11:05
 * @FilePath: \Vue核心技术与实战 - 作业\作业day02\选你爱我求和.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <div>
      <div style="display: inline-block" v-for="(item,index) in arr">
        <input type="checkbox" v-model="newArr" :value="item"/>
        <span>{{item}}</span>
      </div>
      <p>你选中的元素, 累加的值和为: {{total}}</p>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        arr: [9, 15, 19, 25, 29, 31, 48, 57, 62, 79, 87],
        newArr:[]
      },
      computed: {
        total(){
          return this.newArr.reduce((a,b)=>a+b,0)
        }
      },
    })
  </script>
</body>
</html>